package com.inossem.warehousestorage_inossem.activity.receive;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.inossem.utils.listener.NoDoubleClickListener;
import com.inossem.warehousestorage_inossem.R;
import com.inossem.warehousestorage_inossem.activity.base.BaseActivity;
import com.inossem.warehousestorage_inossem.activity.receive.extra.ReceiveExtra;
import com.inossem.warehousestorage_inossem.utils.ActivityUtils;
import com.zhy.android.percent.support.PercentRelativeLayout;

public class ReceiveResultActivity extends BaseActivity {

    private TextView title, message, result;

    private Button inStorage, back;

    private String mMessage, mReceiveNumber;

    private boolean mIsConfirm;

    @Override
    protected void onCreateImpl(Bundle savedInstanceState) {
        setContentView(R.layout.activity_receive_result);
        initView(ReceiveResultActivity.this);
    }

    @Override
    protected void onResumeImpl() {
        initData(ReceiveResultActivity.this);
    }

    private void initView(Activity activity) {
        title = (TextView) activity.findViewById(R.id.headerTitle);
        message = (TextView) activity.findViewById(R.id.message);
        result = (TextView) activity.findViewById(R.id.result);
        inStorage = (Button) activity.findViewById(R.id.inStorage);
        back = (Button) activity.findViewById(R.id.back);
    }

    private void initData(Activity activity) {
        title.setText(activity.getResources().getString(R.string.activity_receive_add_receiver_title));
        PercentRelativeLayout leftTitleLayout = ActivityUtils.initBackAndFunction(activity, R.string.activity_receive_receive_item_title_short, new NoDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View v) {
                finish();
            }
        });
        leftTitleLayout.setVisibility(View.INVISIBLE);
        inStorage.setOnClickListener(new NoDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View v) {
                goReceiveManageActivity(activity, true);
            }
        });
        back.setOnClickListener(new NoDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View v) {
                goReceiveManageActivity(activity, false);
            }
        });
        getExtra(activity);
        getData(activity);
    }

    private void getExtra(Activity activity) {
        mMessage = activity.getIntent().getStringExtra(ReceiveExtra.MESSAGE);
        mReceiveNumber = activity.getIntent().getStringExtra(ReceiveExtra.RECEIVE_NUMBER);
        mIsConfirm = activity.getIntent().getBooleanExtra(ReceiveExtra.IS_CONFIRM, false);
    }

    private void getData(Context context) {
        if (mIsConfirm) {
            message.setText(context.getResources().getString(R.string.activity_receive_result_receive_number) + mReceiveNumber + context.getResources().getString(R.string.activity_receive_result_has_confirmed));
//            message.setText(mMessage);
            result.setText(context.getResources().getString(R.string.activity_receive_result_confirm_success));
        } else {
            message.setText(context.getResources().getString(R.string.activity_receive_result_receive_number) + mReceiveNumber + context.getResources().getString(R.string.activity_receive_result_has_saved));
//            message.setText(mMessage);
            result.setText(context.getResources().getString(R.string.activity_receive_result_save_success));
        }
    }

    private void goReceiveManageActivity(Activity activity, boolean toInStorageFlag) {
        Intent intent = new Intent(activity, ReceiveManageActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.putExtra(ReceiveExtra.TO_IN_STORAGE, toInStorageFlag);
        activity.startActivity(intent);
        activity.finish();
    }

    @Override
    public void onBackPressed() {

    }
}
